import React from 'react';

import './index.less';


export default class Input extends React.PureComponent {
  constructor() {
    super();
    this.state = { };
  }
  handlOnChang=(value, key) => {
    this.props.onChange(value, key);
  }

  render() {
    const { errorMessage, className, label, placeholder, addonBefore, addonAfter, error, inputKey, type } = this.props;
    return (
      <div className={`input-group ${className}`} >
        <label className="input-label">{label || '证书名称'}</label>
        <div className="div-input">
          <span className={`${addonBefore ? 'span-http' : 'span-none'}`}>{addonBefore}</span>
          <input
            className={`inputs ${error ? 'input-error' : ''} ${addonBefore ? 'addonBefore' : ''} ${addonAfter ? 'addonAfter' : ''}`}
            type={type || 'text'}
            value={this.props.value}
            placeholder={placeholder || `请输入${label}`}
            onChange={e => this.handlOnChang(e.target.value, inputKey)}
          />
          <span className={`${addonAfter ? 'span-com' : 'span-none'}`}>{addonAfter}</span>
          {error ? <span className="error-message">{errorMessage || '*必须填'}</span> : ''}
        </div>
      </div>
    );
  }
}
Input.defaultProps = {
  className: 'a',
};
